package com.weijian.listener;

import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Session监听器
 * 用于监控Session的创建和销毁
 */
@Component
@Slf4j
public class SessionListener implements HttpSessionListener {


    //TODO 这里需要看一下是否真的起作用了

    @Override
    public void sessionCreated(HttpSessionEvent event) {
        log.info("Session created: {}", event.getSession().getId());
        log.info("Active sessions: {}", getActiveSessionCount());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        log.info("Session destroyed: {}", event.getSession().getId());
        log.info("Active sessions: {}", getActiveSessionCount());
    }

    /**
     * 获取当前活跃Session数量
     *
     * @return 活跃Session数量
     */
    private int getActiveSessionCount() {
        // 实际数量由Spring Session管理
        return 0;
    }
}